package com.ruanjian.api.controller;

import com.ruanjian.api.bean.Experiment;
import com.ruanjian.api.service.impl.ExperimentServiceImpl;
import com.ruanjian.api.utils.AjaxResult;
import com.ruanjian.api.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author shkstart
 * @create 2022-11-30 8:50
 */
@RestController
@RequestMapping("/api/java/ExperimentSites")
public class ExperimentController extends BaseController{

    @Autowired
    ExperimentServiceImpl experimentService;

    /**
     * 新增实验场次
     * @param experiment
     * @return
     */
    @CrossOrigin
    @PostMapping("/insertSelective")
    public int insertSelective(@RequestBody Experiment experiment){
//        experiment.setExperimentStartTime(new Date(1669771105328L));
//        experiment.setExperimentEndTime(new Date(1669772105328L));
        experiment.setExperimentPublishTime(DateUtil.getNowDate());
        experiment.setExperimentStatus(1);
        return experimentService.insertSelective(experiment);
    }

    /**
     * 删除实验场次
     * @param experimentId 主键id
     * @return
     */
    @CrossOrigin
    @PostMapping("/deleteByPrimaryKey/{experimentId}")
    public int deleteByPrimaryKey( @PathVariable("experimentId") Long experimentId){
        return experimentService.deleteByPrimaryKey(experimentId);
    }

    /**
     * 修改实验场次
     * @param experiment
     * @return
     */
    @CrossOrigin
    @PostMapping("/updateByPrimaryKeySelective")
    public int updateByPrimaryKeySelective(@RequestBody Experiment experiment){
        return experimentService.updateByPrimaryKeySelective(experiment);
    }

    /**
     * 查询
     * @param experiment
     * @return
     */
    @CrossOrigin
    @PostMapping("/selectSelective")
    public AjaxResult selectSelective(@RequestBody Experiment experiment){
        return AjaxResult.success().add("experiment",experimentService.selectSelective(experiment));
    }

}
